<?php

require_once(DIR_LIB."VsGui".DIR_SEP."vssmartywidget.php");
require_once(DIR_LIB."Junona".DIR_SEP."junmodelwork.php");

require_once(dirname(__FILE__).DIR_SEP."vsdateedit.php");

class XCartOperationWorkCountPrint extends VsSmartyWidget {

	function __construct(&$page, $operatorId, $pager=NULL) {
		// Ne go zabravqj ina4e nqma $smarty Object
		parent::__construct();

		$orderBy = isset($_GET['order_by']) ? $_GET['order_by'] : '';

		if(isset($_GET['group_by'])) {
			$groupBy = $_GET['group_by'];

			if($groupBy=='operation')
				$this->_template = dirname(__FILE__).DIR_SEP."xcart_operator_work_groupby_operation_print.html";
			else
				$this->_template = dirname(__FILE__).DIR_SEP."xcart_operator_work_print.html";
		}
		else {
			$groupBy = '';
		
			$this->_template = dirname(__FILE__).DIR_SEP."xcart_operator_work_count_print.html";
		}

		$this->_wwwDir = 'templates/XCart/';
		
		//$page->addCssFile($this->_wwwDir."css/print.css", 'print');

		//$minDate = isset($_POST['fromVsdeDate']) ? $_POST['fromVsdeDate'] : date("Y-m-d", mktime(0, 0, 0, date("m")-1, date("d"),   date("Y")));
		$minDate = isset($_REQUEST['fromVsdeDate']) ? $_REQUEST['fromVsdeDate'] : date("Y-m-d", strtotime("-2 week"));
		$maxDate = isset($_REQUEST['toVsdeDate']) ? $_REQUEST['toVsdeDate'] : date("Y-m-d");
		//echo "FROM: ".$minDate."  TO:  ".$maxDate;
		//echo "FROM: ".$_POST['fromVsdeDate']."  TO:  ".$_POST['toVsdeDate'];

		$fromDateEdit = new VsDateEdit($page, $minDate);
		//$this->assign('fromDateEdit',  $fromDateEdit->show());
		$this->assign('fromVsdeDate',  $fromDateEdit->date());

		$toDateEdit = new VsDateEdit($page, $maxDate);
		//$this->assign('toDateEdit',  $toDateEdit->show());
		$this->assign('toVsdeDate',  $toDateEdit->date());

		
		$modelWork = JunModelWork::makeForView($operatorId, $fromDateEdit->date(), $toDateEdit->date(), $orderBy, $groupBy);

		$this->assign('model', $modelWork->operator());
		$this->assign('opWorkOperations',  $modelWork->operations());
		$this->assign('opWorkTotal',  $modelWork->total());

		if($pager)
			$this->assign('pager', $pager->show());
		else
			$this->assign('pager', '');

		//$ms = VsMessageStack::Instance();
		//$messages = $ms->messages('JunOperatorWork');
		//print_r($messages);
	}
	//===================================================================================================================

	function show() {
		$this->assign('wwwDir', $this->_wwwDir);

		return $this->fetch($this->_template);
	}
	//===================================================================================================================

};

?>
